package com.zm.cc;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zm.cc.entity.Fav;
import com.zm.cc.entity.User;
import com.zm.cc.service.BizException;
import com.zm.cc.service.IFavService;
import com.zm.cc.service.IUserService;
import com.zm.cc.service.impl.UserServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import java.security.PublicKey;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = FavConfig.class)
public class test {
    @Autowired
    IFavService iFavService;
    @Test
    public void test1() throws BizException {
        Fav fav = new Fav();
        fav.setAddr("https://sina.com/");
        fav.setName("新浪");
        fav.setTags("门户;娱乐");
        fav.setUid(1);
        fav.setImage("https://img1.baidu.com/it/u=3138590727,72450821&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500");
        iFavService.add(fav);
    }
    @Autowired
    IUserService dao;

    @Test
    public void test2(){
        Result result = new Result();
        User user = new User();
        user.setId(1);
        user.setUname("zm");
        user.setPwd("123");
        String oldPwd = "123";
        String newPwd = "321";
        if(!(user.getPwd().equals(oldPwd))){
            result.setCode(-2);
            result.setMsg("原密码错误");
            System.out.println("result = " + result);
            return;
        }
        user.setPwd(newPwd);
        boolean state = dao.updateById(user);
        if(state){
            result.setCode(1);
            result.setMsg("修改成功");
            System.out.println("result = " + result);
            return;
        }

        result.setCode(0);
        result.setMsg("修改失败，系统繁忙");
        System.out.println("result = " + result);
    }
}
